import fs from 'fs';

const htmlPath = './dist/index.html'; // 打包后的html文件路径

const htmlText = fs.readFileSync(htmlPath, 'utf8');

const htmlArr = htmlText.split('\n')

const resultArr = [];

htmlArr.forEach((v) => {

 v = v

  .replace(/script ?nomodule\s?/g, 'script ')

  .replace(/\s?crossorigin\s?/g, ' ')

  .replace(/<link rel="modulepreload" href="[^"]+\.js">/g, '')

  .replace(/>[^>]*<\/script>/g, '></script>')

  .replace(/data-src/g, 'src')
  
   .replace(/<script\s*>[^>]*<\/script>/g, '')

 if (!v.includes(`script type="module"`)) {

  resultArr.push(v);

 }

});

fs.writeFileSync(htmlPath, resultArr.join('\n'), 'utf8');
